package inits

import (
	"gitee.com/sineatos/deag/base"
)

// InitRepeat is used to call n times the function fnc and put the result into a slice and return it
func InitRepeat(fnc func() base.Individual, n int) base.Individuals {
	container := make(base.Individuals, n)
	for i := range container {
		container[i] = fnc()
	}
	return container
}

// InitCycle is used to repeat n times the function sequence seq_fnc
func InitCycle(seqFnc []func() base.Individual, n int) base.Individuals {
	container := make(base.Individuals, len(seqFnc)*n)
	count := 0
	for i := 0; i < n; i++ {
		for _, fnc := range seqFnc {
			container[count] = fnc()
			count++
		}
	}
	return container
}

// GenerateFloat64SliceRepeat returns a []float64 which element is generated by fnc()
func GenerateFloat64SliceRepeat(fnc func() float64, n int) []float64 {
	container := make([]float64, n)
	for i := range container {
		container[i] = fnc()
	}
	return container
}

// GenerateIntSliceRepeat returns a []int which element is generated by fnc()
func GenerateIntSliceRepeat(fnc func() int, n int) []int {
	container := make([]int, n)
	for i := range container {
		container[i] = fnc()
	}
	return container
}

// GenerateBoolSliceRepeat returns a []bool which element is generated by fnc()
func GenerateBoolSliceRepeat(fnc func() bool, n int) []bool {
	container := make([]bool, n)
	for i := range container {
		container[i] = fnc()
	}
	return container
}
